package coder.nav.sdk;

import coder.nav.utils.HttpUtils;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class WxPusherAPI {

    private static final String API = "https://wxpusher.zjiecode.com/api/send/message";

    private static final String TOKEN = "AT_n397Wx0AbQ6vkhyVoM8e7BuuMqx6Pygn";

    public static boolean sendMessage(String uid, String title, String context) {
        if(StringUtils.isBlank(context)) {
            context = title;
        }
        context += "<div style='padding-bottom: 1000px;'></div>";
        Map<String, Object> params = new HashMap<>();
        params.put("appToken", TOKEN);
        params.put("url", "");
        params.put("topicIds", null);
        params.put("contentType", 2);
        params.put("verifyPayType", 0);
        params.put("uids", Collections.singletonList(uid));
        params.put("summary", title);
        params.put("content", context);
        String response = HttpUtils.sendPostRequest(API, params, null);
        JSONObject json = JSONObject.parse(response);
        try {
            if(json.getInteger("code") == 1000) {
                return true;
            }
        } catch(Exception ignored) {}
        return false;
    }

}
